package com.ms.education.exceptionHandler;

import com.ms.education.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author msjava
 * @date 2022/1/5 18:46
 */
@RestControllerAdvice
@Slf4j
@Order(5)
public class GlobalException {

    //自定义异常
    @ExceptionHandler(EduException.class)
    public R error(EduException e){
        e.printStackTrace();
        return R.error().code(e.getCode()).message(e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }
}
